package projcet.test.student.student;

import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AddOtherActivity extends AppCompatActivity {



    private DbOpenHelper mHelper;
    String teacher;
    String subject;
    EditText ed_add_teacher;
    EditText ed_add__subject;
    Button bt_add_other;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_other);
        mHelper = new DbOpenHelper(this);
        ed_add__subject=findViewById(R.id.ed_add__subject);
        ed_add_teacher=findViewById(R.id.ed_add_teacher);
        bt_add_other=findViewById(R.id.bt_add_other);
        /**
         * 添加教师与科目
         */
        bt_add_other.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                teacher=ed_add_teacher.getText().toString();
                subject=ed_add__subject.getText().toString();
                if(TextUtils.isEmpty(teacher)) {
                    Toast.makeText(AddOtherActivity.this, "请输入教师", Toast.LENGTH_SHORT).show();
                } else  if(TextUtils.isEmpty(teacher)) {
                    Toast.makeText(AddOtherActivity.this, "请输入科目", Toast.LENGTH_SHORT).show();

                }else {
                    SQLiteDatabase db = mHelper.getWritableDatabase();
                    ContentValues values = new ContentValues();
                    values.put("teacher", teacher);
                    values.put("subject", subject);
                    db.insert("Teacher", null, values);
                    values.clear();
                    db.close();

                    Toast.makeText(AddOtherActivity.this, "添加成功", Toast.LENGTH_SHORT).show();

                }
            }
        });

    }


}
